package days29.Title104;


class Solution {
    private int maxDepth;
    private int depth = 0;

    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        dfs(root);
        return maxDepth;
    }

    public void dfs(TreeNode root) {
        if (root != null) {
            depth++;
            if (depth > maxDepth) maxDepth = depth;
            dfs(root.left);
            dfs(root.right);
            depth--;
        }
    }
}
